﻿namespace LiteBlog.Components.Helpers
{
    using System.Web.Caching;
    using LiteBlog.Common.Enums;
    using LiteBlog.Repositories.Contracts;
    using LiteBlog.Components.Enums;
    using LiteBlog.Components.Contracts;
    using Repositories.Common;

    public class CacheContext : ICacheContext
    {
        private IDataContext _context;
        public CacheContext(IDataContext context)
        {
            _context = context;
        }

        public CacheDependency GetDependency(CacheType type)
        {
            return this.GetDependency(type, string.Empty);
        }

        public CacheDependency GetDependency(CacheType type, string id)
        {
            string path = string.Empty;
            switch (type)
            {
                case CacheType.Archive:
                    path = _context.GetPath(DataStoreType.Archive, null);
                    break;
                case CacheType.Blog:
                    path = _context.GetPath(DataStoreType.Blog, null);
                    break;
                case CacheType.Categories:
                    path = _context.GetPath(DataStoreType.Category, null);
                    break;
                case CacheType.Settings:
                    path = _context.GetPath(DataStoreType.Settings, null);
                    break;
                case CacheType.Pages:
                    path = _context.GetPath(DataStoreType.Pages, null);
                    break;
                case CacheType.Page:
                    path = _context.GetPath(DataStoreType.Page, id);
                    break;
                case CacheType.Post:
                    path = _context.GetPath(DataStoreType.Post, id);
                    break;
                case CacheType.Comments:
                    path = _context.GetPath(DataStoreType.Comment, null);
                    break;
                case CacheType.Tags:
                    path = _context.GetPath(DataStoreType.Tags, null);
                    break;
                }
            return !string.IsNullOrEmpty(path) ? new CacheDependency(path) : null;
        }
    }
}